<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    div {
      width: 300px;
      border: 1px solid #ccc;
      margin: 50px auto;
      padding: 10px;
    }

    textarea,
    button {
      display: inline-block;
      width: 100%;
      padding: 0;
      margin: 0;
    }
  </style>
</head>

<body>
  <div>
    <textarea placeholder="请输入评论信息" name="" id="" cols="30" rows="10"></textarea>
    <button>发布</button>

    <h2>暂无评论</h2>
    <ul></ul>
  </div>

  <script>
    var textarea = document.querySelector('textarea')
    var button = document.querySelector('button')
    var ul = document.querySelector('ul')
    var h2 = document.querySelector('h2')

    button.onclick = function () {
      if (textarea.value === '') {
        return alert('请输入内容')
      }
      
      var li = document.createElement('li')
      li.innerText = textarea.value

      li.onclick = function() {
        this.parentNode.removeChild(this)
      }

      // ul.appendChild(li)
      ul.insertBefore(li, ul.firstElementChild)
      h2.style.display = 'none'

      textarea.value = ''
    }


  </script>
</body>

</html>